home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / tweak16b.zip / DETECT.CPP < prev    next >
C/C++ Source or Header  |  1993-11-26  |  4KB  |  136 lines

  1. /*
  2.  *    Mode detection:
  3.  *    ---------------
  4.  *    Currently incompatible with CGA and Hercules modes.
  5.  *        200-line CGA modes are detected as 100-line.
  6.  *        640x200x2 is detected as 16-color.
  7.  *        Hercules not supported at all.
  8.  *    Monochrome EGA/VGA modes are also *not* supported, due to use of
  9.  *        different port addresses.
  10.  *
  11.  *    Variables of interest:
  12.  *        hPixels, vPixels - the actual resolution of the mode, in characters
  13.  *            in text modes, in pixels in graphics modes.
  14.  *        adrOffset - the number of addressable bytes between two vertically
  15.  *            adjacent pixels, or words between two vertically adjacent
  16.  *            characters in text mode.
  17.  *
  18.  */
  19.  
  20. #include "detect.hpp"
  21. #include "screen.hpp"
  22. #include <dos.h>
  23. #include <conio.h>
  24.  
  25.  
  26.  
  27. void ModeInfo::detectFrom(RegisterTable ®Table)
  28.     {
  29.     Register *GCMode = regTable.getRegister(GRACON_ADDR, 0x05);
  30.     Register *GCMisc = regTable.getRegister(GRACON_ADDR, 0x06);
  31.     Register *ACMode = regTable.getRegister(ATTRCON_ADDR, 0x10);
  32.     Register *CRTChde = regTable.getRegister(CRTC_ADDR, 0x01);
  33.     Register *CRTCoflo = regTable.getRegister(CRTC_ADDR, 0x07);
  34.     Register *CRTCscan = regTable.getRegister(CRTC_ADDR, 0x09);
  35.     Register *CRTCvde = regTable.getRegister(CRTC_ADDR, 0x12);
  36.     Register *CRTCoffs = regTable.getRegister(CRTC_ADDR, 0x13);
  37.     Register *CRTCmode = regTable.getRegister(CRTC_ADDR, 0x17);
  38.     Register *SEQmmode = regTable.getRegister(SEQ_ADDR, 0x04);
  39.  
  40.     int temp;
  41.     switch ((*GCMode)(5,2))
  42.         {
  43.         case 0:
  44.             colors = COLOR16;        // might also be COLOR2 !!!
  45.             hPixelsPerClock = 8;
  46.             break;
  47.         case 1:
  48.             colors = COLOR4;
  49.             hPixelsPerClock = 16;
  50.             break;
  51.         case 2:
  52.             colors = COLOR256;
  53.             hPixelsPerClock = 4;
  54.             break;
  55.         }
  56.  
  57.     temp = (**GCMisc & 1 != 0);
  58.     if (temp == (**ACMode & 1 != 0))
  59.         alphaGraph = temp ? GRAPHICS : ALPHA;
  60.     else
  61.         alphaGraph = AG_CONFLICT;
  62.  
  63.     if (alphaGraph == ALPHA)
  64.         hPixelsPerClock = 1;
  65.  
  66.     chain4 = (*SEQmmode)(3,1);
  67.     countBy2 = (*CRTCmode)(3,1);
  68.     adrOffset = **CRTCoffs * 2 * (countBy2+1);
  69.  
  70.     hClocks = **CRTChde + 1;
  71.     vClocks =
  72.         (**CRTCvde | ((*CRTCoflo)(1,1) << 8) | ((*CRTCoflo)(6,1) << 9)) + 1;
  73.  
  74.     xres = hClocks * hPixelsPerClock;
  75.     vxresBytes = vxres = adrOffset * hPixelsPerClock;
  76.  
  77.     if (alphaGraph == ALPHA)
  78.         vxresBytes *= 2;
  79.     else
  80.         if (alphaGraph == GRAPHICS)
  81.             if (colors == COLOR16)
  82.                 vxresBytes /= 8;
  83.             else
  84.                 if (colors == COLOR256 && !chain4)
  85.                     vxresBytes /= 4;
  86.  
  87.     lineClocks = (*CRTCscan)(0,4) + 1;
  88.     if ((*CRTCscan)(7,1) << 5)
  89.         lineClocks *= 2;
  90.     yres = vClocks / lineClocks;
  91.     spareClocks = vClocks % lineClocks;
  92.     vyres = (alphaGraph == GRAPHICS ? 65536L : 32768L) / vxresBytes;
  93.     xpages = float(vxres)/xres;
  94.     ypages = float(vyres)/yres;
  95.     }
  96.  
  97.  
  98. GraphicsAPI *ModeInfo::getGraphicsAPI()
  99.     {
  100.     if (alphaGraph == GRAPHICS)
  101.         switch(colors)
  102.             {
  103.             case COLOR16:
  104.                 return new Planar16(xres, yres, vxres);
  105.             case COLOR256:
  106.                 if (chain4)
  107.                     return new Chained256(xres, yres, vxres);
  108.                 else
  109.                     return new Unchained256(xres, yres, vxres);
  110.             }
  111.     return 0;
  112.     }
  113.  
  114. void ModeInfo::show()
  115.     {
  116.     window(editWidth/2+2, editHeight-18, editWidth, editHeight-7);
  117.     clrscr();
  118.     textattr(INFO_COLOR);
  119.     cprintf("This seems to be a %d-color\n\r"
  120.             "%s mode.\n\r\n\r"
  121.             "Physical resolution: %d x %d\n\r"
  122.             "Virtual resolution:  %d x %d\n\r\n\r"
  123.             "Page resolution:     %3.1f x %3.1f",
  124.             colors,
  125.             alphaGraph==ALPHA ? "text" :
  126.                 alphaGraph==GRAPHICS ? (chain4 ? "linear graphics" :
  127.                                                  "planar graphics") :
  128.                                        "graph/text conflict",
  129.             xres, yres,
  130.             vxres, vyres,
  131.             xpages, ypages
  132.             );
  133.     window(1,1,editWidth,editHeight);
  134.     }
  135.  
  136.